name: Python MyPy Check

on:
  push:
    branches:
      - master
  pull_request:
    types: [opened, reopened]

jobs:
  mypy:
    runs-on: ubuntu-latest

    steps:
    - name: Check out code
      uses: actions/checkout@v2

    - name: Set up Python
      uses: actions/setup-python@v2
      with:
        python-version: 3.11

    - name: Install dependencies
      run: |
        pip install poetry
        poetry install

    - name: Run MyPy
      run: |
        poetry run mypy --strict ./src > mypy_output.txt
      continue-on-error: true

    - name: Check MyPy results
      run: |
        cat mypy_output.txt
        if ! grep -q "Success: no issues found in" mypy_output.txt; then
          echo "MyPy issues found!"
          exit 1
        fi
